﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ZLCMS.Business.Util;
using ZLCMS.Data.Model;
using ZLCMS.Data.Common;
using NHibernate.Criterion;
using NHibernate;
using ZLCMS.Business;
using ZLCMS.Data;
using DotNet.Common.NHibernateUtil;

namespace ZLCMS.Web.ShopCart
{
    public partial class ShoppingCartComfirmSuccess : System.Web.UI.Page
    {
        protected ShopOrderInfo _ordersDB;//当前订单信息
        protected ShopShippingInfo _shippingDB;//当前配送方式
        protected ShopPaymentInfo _paymentDB;//当前付费方式
        protected MemberInfo _memberDB;//当前订单购买会员信息

        //protected decimal _hxffje
        //{
        //    get
        //    {
        //        decimal dxdjq = _ordersDB.Dxdjq.HasValue ? _ordersDB.Dxdjq.Value : 0.00M;
        //        decimal advancepayment = _ordersDB.Advancepayment.HasValue ? _ordersDB.Advancepayment.Value : 0.00M;
        //        return _ordersDB.Totalprice - dxdjq - advancepayment;
        //    }
        //}

        protected void Page_Load(object sender, EventArgs e)
        {
            //初始化全局变量值
            InitializeGlobalValue();
        }

        protected void InitializeGlobalValue()
        {
            _memberDB = Master.LoadMember();

            using (ISession session = SessionFactoryHelper.CreateSession())
            {
                if (!string.IsNullOrEmpty(Request["id"]))
                {
                    _ordersDB = session.CreateCriteria<ShopOrderInfo>().Add(Expression.Eq("Id", int.Parse(Request["id"]))).Add(Expression.Eq("MemberAccount", _memberDB.AccountId)).UniqueResult<ShopOrderInfo>();
                }
                if (_ordersDB == null && !string.IsNullOrEmpty(Request["o"]))
                {
                    _ordersDB = session.CreateCriteria<ShopOrderInfo>().Add(Expression.Eq("OrderNo", Request["o"])).Add(Expression.Eq("MemberAccount", _memberDB.AccountId)).UniqueResult<ShopOrderInfo>();
                }
                if (_ordersDB == null)
                {
                    Response.Redirect("/ShowNotice.aspx?c=找不到对应数据。");
                }

                _shippingDB = session.Get<ShopShippingInfo>(int.Parse(_ordersDB.ShippingType));
                _paymentDB = session.Get<ShopPaymentInfo>(int.Parse(_ordersDB.PaymentType));

                IQuery query = session.CreateQuery("from ShopOrderProduct o, ProductInfo p where o.ProductId = p.Id and o.OrderId = :OrderId").SetParameter("OrderId", _ordersDB.Id);
                rp_productlist.DataSource = query.List();
                rp_productlist.DataBind();
            }
        }
    }
}
